#!/bin/bash

DIALOG=~/command/lxdialog
FILES=($(ls -A))
FLAG=("[ ]" "[X]" )
BOX_HEIGHT=25
BOX_WIDTH=60
LIST_HEIGHT=18 
MIN_BOX_HEIGHT=10 

function show_help()
{
	$DIALOG --title "help" --textbox ${FILES[$1]} $BOX_HEIGHT $BOX_WIDTH
}

function confirm_msg()
{
	rs="$1"
	i=0
	for x in $rs;do
		if [ "$x" == "1" ];then
			tip="$tip ${FILES[$i]}"
		fi
		((i++))
	done
	if $DIALOG --title "tip" --yesno "confirm to delete:$tip" $MIN_BOX_HEIGHT $BOX_WIDTH;then
		for x in $tip;do
			echo delete $x
		done
	fi
}



function main()
{
	for ((i=0;i<${#FILES[*]};i++));do
		FLAGS[$i]=0
	done

	sel="0"
	cmd_head="$DIALOG --title 'title' --menu 'discription' $BOX_HEIGHT $BOX_WIDTH $LIST_HEIGHT"

	while true
	do
		i=0
		list=
		for x in ${FILES[*]};do
			list="$list '$i'  '${FLAG[${FLAGS[$i]}]}  $x'"
			((i++))
		done
		list="$list 2>rs.out"

	 	cmd="$cmd_head $sel $list"
	 	eval $cmd
		
		ret=$?

		case "$ret" in
		0)
		for x in ${FLAGS[*]};do
			if [ $x == '1' ];then
				confirm_msg "${FLAGS[*]}"
				break
			fi
		done
		break
		;;
		1|255)
			break;;
		2)
			show_help;;
		6)
			sel=$(cat rs.out)
			FLAGS[$sel]=1;;
		esac
	done
	rm -f rs.out
}

main
